﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight;
using System.Collections.ObjectModel;
namespace AgileLogistics.ViewModel
{
   public  class PollViewModel:ViewModelBase
    {

        Model.Repository<Model.Menus> MenuRep = new Model.Repository<Model.Menus>();
        public PollViewModel()
        {
            CurrentPoll = new Model.Poll() {
                StartDate = DateTime.Now.Date,
                EndDate = DateTime.Now.AddDays(1),
            };

            PollItems = new ObservableCollection<Model.PollItem>();
            ZhucaiMenu = new ObservableCollection<Model.PollItem>();
            ZhushiMenu = new ObservableCollection<Model.PollItem>();
            TangMenu = new ObservableCollection<Model.PollItem>();

            Menus = new ObservableCollection<Model.Menus>( MenuRep.GetList());
        }


        #region 创建投票
        public Model.Poll CurrentPoll { get; set; }
        public ObservableCollection<Model.PollItem> PollItems { get; set; }


        public ObservableCollection<Model.Menus> Menus { get; set; }


        public ObservableCollection<Model.PollItem> ZhucaiMenu { get; set; }
        public ObservableCollection<Model.PollItem> ZhushiMenu { get; set; }
        public ObservableCollection<Model.PollItem> TangMenu { get; set; }

        //当前类型ID
        public int ClassID = 2;


        /// <summary>
        /// 菜品转化为投票选项
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        public Model.PollItem MenuToPollItem(Model.Menus menu)
        {
            Model.PollItem pollItem = new Model.PollItem
            {
                MenuId = menu.Id,
                MenuName = menu.Name,
                ClassId = (int)menu.ClassId,
                ClassName =  (new Model.DBContext()).DB.Queryable<Model.MenuClass>().Where(c=>c.Id==menu.ClassId).First().Name,
                PollId = CurrentPoll.Id,

            };

            return pollItem;
        }
        #endregion



        #region 读取投票

        //
        public int CanyuCount { get; set; }
        public int TouPiaoCount { get; set; }
        public int FangwenCount { get; set; }


        #endregion


        public ObservableCollection<Model.Poll> Polls = new ObservableCollection<Model.Poll>();
        public ObservableCollection<Model.Poll> HistoryPolls { get; set; }




    }
}
